package com.baseEnum;

/**
 * @Author ri.yang
 * @Since 2016/1/6.
 */
public enum CourseType implements BaseEnum {
    COMPULSORY(1, "必修课"),
    SELECTIVE(2, "选修课");

    private int value;
    private String name;

    CourseType(int value, String name) {
        this.value = value;
        this.name = name;
    }

    static {
        SystemEnum.register(new SystemEnum("courseType") {
            @Override
            public BaseEnum getEnum(int value) {
                BaseEnum[] enums = values();
                for (BaseEnum be : enums) {
                    if (be.getValue() == value) {
                        return be;
                    }
                }
                return null;
            }
        });
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public static CourseType get(Integer value){
        if (value == null){
            return COMPULSORY;
        }
        for (CourseType courseType : values()) {
            if (value == courseType.getValue()){
                return courseType;
            }
        }
        throw new RuntimeException("courseType value not exists");
    }

}
